#include "bitmaptileset.hpp"
#include "resourcehandler.hpp"
#include "tilelayer.hpp"

namespace nmc
{
	BitmapTileSet::BitmapTileSet(const std::string& filename)
	{
		mTiles = ResourceHandler::getInstance()->getBitmap(filename);
	}

	BitmapTileSet::~BitmapTileSet()
	{
	}

	void BitmapTileSet::drawTile(BITMAP *dest, int x, int y, int tile)
	{
		int w = mTiles->w / TileLayer::TILE_SIZE;
		int h = mTiles->h / TileLayer::TILE_SIZE;
		
		if (tile > 0 && tile < w * h)	
		{
			int sx = (tile % w) * TileLayer::TILE_SIZE;
			int sy = (tile / w) * TileLayer::TILE_SIZE;
			blit(mTiles, dest, sx, sy, x, y, TileLayer::TILE_SIZE, TileLayer::TILE_SIZE);
		}
	}
}